<?php
class Controller_Admin_App extends Controller_Template
{
    public function __construct ($req, $res)
    {
        $this->template = 'smarty:app/downloads/default';
        parent::__construct($req, $res);
    }

    public function action_index ()
    {
    }

    public function action_downloads ($pname = NULL, $start_day = NULL, $stop_day = NULL)
    {
        if (empty($start_day))
            $start_day = date("Ymd", time() - 86400 * 14);
        if (empty($stop_day))
            $stop_day  = date("Ymd", time() - 86400);

        $pname     = trim($pname);
        $start_day = date("Ymd", strtotime($start_day));
        $stop_day  = date("Ymd", strtotime($stop_day));

        $this->template->set('pname',   $pname);
        $this->template->set('day', array('start' => $start_day, 'stop' => $stop_day));
        if (! empty($pname))
        {
            $downloads = App_Downloads::lists($pname, $start_day, $stop_day);
            $this->template->set('downloads', $downloads);
            $this->template->set('package', App_Info::basic($pname));
        }

    }
}
